import { ref } from "vue";
import type { Ref } from "vue";
import { defineStore } from "pinia";
import type { CateVO } from "@/types/categoryType";
import { fetchCategoryAPI } from "@/api/categoryAPI";


const useCategoryStore = defineStore("categoryStore", () => {

   // 分类
   const cateList: Ref<CateVO[]> = ref<CateVO[]>([]);
   // 发送请求获取分类的回调函数
   const fetchCateList = async ():Promise<void> => {
      try {
         const { result }: { result: CateVO[] } = await fetchCategoryAPI();
         cateList.value = result;
      } catch (error: any) {
         await error;
      }
   };
   return {
      cateList,
      fetchCateList,
   };
});


export default useCategoryStore;